﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using VisaCRM.Modules.Admin.Model;
using VisaCRM.Common.Helper;

namespace VisaCRM.Modules.Admin.Gateway
{
    class TitleGateway
    {
        internal System.Collections.ObjectModel.ObservableCollection<Title> GetAllTitles()
        {
            ObservableCollection<Title> allTitle = new ObservableCollection<Title>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchTitleList());
            if (dt.Rows.Count <= 0)
            {
                return allTitle;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                allTitle.Add(new Title()
                {
                    TitleID = Convert.ToInt32(dataRow["Title_ID"].ToString()),
                    TitleText = dataRow["Title_Text"].ToString(),
                    TitleGender = Convert.ToInt32(dataRow["Title_Gender"].ToString()),
                    TitleDiscontinued = Convert.ToInt32(dataRow["Title_Discontinued"].ToString())
                });
            }
            return allTitle;
        }

       
        internal void SaveNewTitleToDatabase(string ttext, int tgen)
        {
            string query = QueryProvider.MakeSQLQueryToInsertTitleToDatabase(ttext,tgen);
            DBHelper.ExecuteSqlQuery(query);
        }

        internal void DeleteTitleFromDatabase(int rowid)
        {
            string query = QueryProvider.MakeSQLQueryToDeleteTitleFromDatabase(rowid);
            DBHelper.ExecuteSqlQuery(query);
        }

        internal void EditTitleToDatabase(int rowid, string ttext, int tgen)
        {
            string query = QueryProvider.MakeSQLQueryToEditTitleToDatabase(rowid, ttext, tgen);
            DBHelper.ExecuteSqlQuery(query);
        }

        internal ObservableCollection<string> GetAllGender()
        {
            ObservableCollection<string> allgender = new ObservableCollection<string>();
            allgender.Add("Male");
            allgender.Add("Female");
            return allgender;
        }
    }
}
